<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>订单详情</title>
		<meta name="viewport" content="initial-scale=1, maximum-scale=1">
		<link rel="shortcut icon" href="/favicon.ico">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<script src="js/address.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/jquery-1.11.3.min.js" type="text/javascript" charset="utf-8"></script>
		<style type="text/css">
			* {
				margin: 0px;
				padding: 0px;
			}
			
			.set_height {
				width: 100%;
				background-color: whitesmoke;
				margin-top: 1rem;
			}
			
			.name_phone {
				width: 90%;
				float: left;
				margin-left: 5%;
			}
			
			.name_phone_left {
				float: left;
				padding-top: 0.5rem;
			}
			
			.name_phone_right {
				float: right;
				padding-top: 0.5rem;
			}
			
			.select_address {
				margin-top: 1rem;
				width: 90%;
				float: left;
				margin-left: 5%;
				padding-bottom: 1rem;
			}
			
			.selsec_address_default {
				float: left;
				width: 90%;
				margin-left: 5%;
				padding-bottom: 1rem;
			}
			
			.address {
				width: 100%;
				float: left;
				background-color: whitesmoke
			}
			#order_text{
				float: left;
				margin-top: 1rem;
				width: 100%;
				background-color: whitesmoke
			}
			#oredr_text_box{
				float: left;
				width: 90%;
				margin-left: 5%;
			}
			#img_pic{
				width: 5rem;
				height: 5rem;
				padding-bottom: 1rem;
				margin-top: 0.5rem;
			}
		</style>
		<script type="text/javascript">
			var click = false;
			var addressid;
			var onlyId = 33;
			var awardId = 7;
			$(function() {
				function getUrlParam(name) {
					var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
					var r = window.location.search.substr(1).match(reg); //匹配目标参数
					if (r != null) return unescape(r[2]);
					return null; //返回参数值
				}
				addressid = getUrlParam('id');
				
//				var onlyId = getUrlParam('onlyId');

//				var awardId = getUrlParam('awardId');
				
				
				if (addressid == null) {
					addressid = 0;
					$.ajax({
						type: "get",
						url: http_open + "/foot/user/getAwardOrder?id="+onlyId+"&awardId="+awardId+"&addressId=" + addressid,
						async: true,
						success: function(req) {
							console.log(req)
							var text_box;
							
							if (req.data.address == "") {
								text_box = $("<p style='padding-top: 1rem;padding-bottom: 1rem;'>点击添加收货地址</p>");
								click = false;
							} else {
								addressid = req.data.address.id
								var address = req.data.address.address;
								var phoneNumber = req.data.address.phone;
								var name = req.data.address.name;
								text_box = $("<div id='adress_box' style='float: left;width: 100%;'><p id='name' style='padding-top: 1rem;'>收货人：" + name + "</p><p id='phone' style='padding-top: 0.4rem;'>电话：" + phoneNumber + "</p><p id='address_text' style='padding-top: 0.4rem;padding-bottom: 1rem;'>收货地址：" + address + "</p></div>");
								click = true;
							}
							$("#set_address").append(text_box);
							var order_text = $("<div style='float: left;'><img id='img_pic'src='"+http_open+"/"+req.data.awardImg+"' /></div><div style='float: left;width: 65%;padding-bottom: 1rem;'><div style='padding-left: 1rem;font-size: 18px;padding-top: 1rem;width: 100%;'>"+req.data.awardContent+"</div><div style='padding-left: 1rem;color:gray;width: 100%;font-size: 14px;'></div><div style='padding-left: 1rem;width: 100%;color: red;'></div></div>")
							$("#oredr_text_box").append(order_text);
							var money = req.data.money;
							$("#money span").html(money);
						},
						error: function() {
							alert("链接错误");
						}
					});
				} else {
					addressid = addressid;
					$.ajax({
						type: "get",
						url: http_open + "/foot/user/getAwardOrder?id="+onlyId+"&awardId="+awardId+"&addressId=" + addressid,
						async: true,
						success: function(req) {
							addressid = req.data.address.id
							var text_box;
							var address = req.data.address.address;
							var phoneNumber = req.data.address.phone;
							var name = req.data.address.name;
							text_box = $("<div id='adress_box' style='float: left;width: 100%;'><p id='name' style='padding-top: 1rem;'>收货人：" + name + "</p><p id='phone' style='padding-top: 0.4rem;'>电话：" + phoneNumber + "</p><p id='address_text' style='padding-top: 0.4rem;padding-bottom: 1rem;'>收货地址：" + address + "</p></div>");
							$("#set_address").append(text_box);
							var order_text = $("<div style='float: left;'><img id='img_pic'src='"+http_open+"/"+req.data.awardImg+"' /></div><div style='float: left;width: 65%;padding-bottom: 1rem;'><div style='padding-left: 1rem;font-size: 18px;padding-top: 1rem;width: 100%;'>"+req.data.awardContent+"</div><div style='padding-left: 1rem;color:gray;width: 100%;font-size: 14px;'></div><div style='padding-left: 1rem;width: 100%;color: red;'></div></div>")
							$("#oredr_text_box").append(order_text);
							click = true;
							var money = req.data.money;
							$("#money span").html(money);
						},
						error: function() {
							alert("链接错误");
						}
					});
				}
			})
		</script>
	</head>

	<body>
		<div class="address">
			<div id="set_address" style="float: left;width: 90%;margin-left: 5%;"></div>
			<br style='clear:both;' />
		</div>
		<div style="float: left;height: 5px;width: 100%;background-color: #0099CC;"></div>

		<div id="order_text">
			<div id="oredr_text_box"></div>
		</div>
		<div style="float: left;margin-top: 1rem;width: 100%;background-color: whitesmoke;height: 3rem;line-height: 3rem;">
			<div style="width: 90%;margin-left: 5%;">
				<p style="float: left;">配送费用</p>
				<p id="money" style="float: right;color: red;font-size: 18px;">￥<span></span></p>
			</div>
		</div>
		<div id="touchBuy" style="width: 100%;position: absolute;bottom: 0px;height: 3rem;background-color: royalblue;color: white;text-align: center;line-height: 3rem;">立即支付</div>
	</body>
	<script type="text/javascript">
		$(".address").click(function() {
			window.location.href = "selectAddress.html";
		});
		$("#touchBuy").click(function(){
			if(click == false){
				alert("请选择收货地址");
				return;
			}
			$.ajax({
				type:"get",
				url:http_open+"/foot/user/saveOrder?id="+onlyId+"&awardId="+awardId+"&addressId=" + addressid,
				async:true,
				success:function(req){
					alert("提交成功");
					window.location.href = "payment.html?openId="+req.data.openId+"&orderMoney="+req.data.orderMoney+"&status=1";
				},
				error:function(){
					alert("提交失败");
				}
			});
		});
	</script>

</html>